/// @tags: SegTreeDiv UFS
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stack>
#include <vector>
#define id(i, j) (((i)-1) * n + (j))

using namespace std;

namespace BlueQuantum {

int const N = 2e2 + 5, M = 1e4 + 5;
int const dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};

struct Node {
  int x, y;
  bool c;
  Node(int x, int y, int c) : x(x), y(y), c(c) {}
};

struct UFSNode {
  int x, dep;
  UFSNode(int x, int dep) : x(x), dep(dep) {}
};

int n, m, cnt;
int f[N * N], dep[N * N], pre[N * N], ans[2];
int mp[N][N];
vector<Node> vec[1 << 15];
stack<UFSNode> stk;

inline int find(int x) {
  while (f[x] != x) x = f[x];
  return x;
}

void modify(int x, int l, int r, int L, int R, Node const &v) {
  if (L <= l && r <= R) return vec[x].push_back(v);
  int mid = (l + r) >> 1;
  if (L <= mid) modify(x << 1, l, mid, L, R, v);
  if (mid < R) modify(x << 1 | 1, mid + 1, r, L, R, v);
}

inline bool merge(int x, int y) {
  x = find(x), y = find(y);
  if (x != y) {
    if (dep[x] > dep[y]) swap(x, y);
    stk.push(UFSNode(x, dep[x] == dep[y]));
    f[x] = y;
    dep[y] += dep[x] == dep[y];
    return true;
  }
  return false;
}

void solve(int x, int l, int r) {
  int siz = stk.size(), ans0 = ans[0], ans1 = ans[1];
  for (vector<Node>::iterator it = vec[x].begin(); it != vec[x].end(); ++it) {
    ++ans[it->c];
    mp[it->x][it->y] = it->c;
    for (int i = 0, tx, ty; i < 4; ++i) {
      if ((tx = it->x + dx[i]) > 0 && tx <= n && (ty = it->y + dy[i]) > 0 && ty <= n &&
          mp[tx][ty] == mp[it->x][it->y])
        if (merge(id(it->x, it->y), id(tx, ty))) ans[it->c]--;
    }
  }
  if (l == r) cout << ans[1] << ' ' << ans[0] << '\n';
  else {
    int mid = (l + r) >> 1;
    solve(x << 1, l, mid), solve(x << 1 | 1, mid + 1, r);
  }
  ans[0] = ans0, ans[1] = ans1;
  for (vector<Node>::iterator it = vec[x].begin(); it != vec[x].end(); ++it)
    mp[it->x][it->y] = -1;
  while (int(stk.size()) > siz) {
    dep[f[stk.top().x]] -= stk.top().dep;
    f[stk.top().x] = stk.top().x;
    stk.pop();
  }
}

inline int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      cin >> mp[i][j], pre[id(i, j)] = 1, f[id(i, j)] = id(i, j);
  cin >> m;
  for (int i = 1, x, y; i <= m; ++i) {
    cin >> x >> y;
    if (i != 1)
      modify(1, 1, m, pre[id(x, y)], i - 1, Node(x, y, mp[x][y])), pre[id(x, y)] = i;
    mp[x][y] ^= 1;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) modify(1, 1, m, pre[id(i, j)], m, Node(i, j, mp[i][j]));
  memset(mp, -1, sizeof(mp));
  solve(1, 1, m);
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P4121 [WC2005] 双面棋盘.in", "r", stdin);
  freopen("P4121 [WC2005] 双面棋盘.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
